package main

import (
	"fmt"
	"sort"
)

func sortIntAsc(slice []int) []int {
	// 12, 34, 37, 35, 556, 36, 2
	for i := 0; i < len(slice); i++ {
		for j := i + 1; j < len(slice); j++ {
			if slice[i] > slice[j] {
				slice[i], slice[j] = slice[j], slice[i]
			}
		}
	}
	return slice
}

func sortIntDesc(slice []int) []int {
	// 12, 34, 37, 35, 556, 36, 2
	for i := 0; i < len(slice); i++ {
		for j := i + 1; j < len(slice); j++ {
			if slice[i] < slice[j] {
				slice[i], slice[j] = slice[j], slice[i]
			}
		}
	}
	return slice
}

func mapSort(map1 map[string]string) string {
	var sliceKey []string
	for k, _ := range map1 {
		fmt.Println(k)
		//将mapkey放置入切片中
		sliceKey = append(sliceKey, k)
	}
	sort.Strings(sliceKey)
	var str string
	for _, v := range sliceKey {
		str += fmt.Sprintf("%v=>%v", v, map1[v])
	}
	return str
}

func main() {

	slice1 := []int{12, 2, 55, 23, 99, 1}
	fmt.Println(sortIntAsc(slice1)) //[1 2 12 23 55 99]
	slice2 := []int{12, 2, 55, 23, 99, 1}
	fmt.Println(sortIntDesc(slice2))
	// mapSort(map[string]string{"a": "1", "b": "2", "c": "3"})
	mapString := map[string]string{"asd": "1", "ase": "222", "abb": "333", "aca": "444", "abca": "333"}
	fmt.Println(mapSort(mapString)) // test=>111test2=>222test3=>333
}
